package com.bootdo.blog.dao;

import com.bootdo.blog.domain.HarvestDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:31
 */
@Mapper
public interface HarvestMapper {

	@Select("select `harvest_id`, `batch`, `varieties`, `harvest_time`, `number`, `principal`, `telephone`, `plot_number` from tb_harvest where harvest_id = #{id}")
	HarvestDO get(Integer harvestId);
	
	@Select("<script>" +
	"select * from tb_harvest " + 
			"<where>" + 
		  		  "<if test=\"harvestId != null and harvestId != ''\">"+ "and harvest_id = #{harvestId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"harvestTime != null and harvestTime != ''\">"+ "and harvest_time = #{harvestTime} " + "</if>" + 
		  		  "<if test=\"number != null and number != ''\">"+ "and number = #{number} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"plotNumber != null and plotNumber != ''\">"+ "and plot_number = #{plotNumber} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by harvest_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<HarvestDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_harvest " + 
			"<where>" + 
		  		  "<if test=\"harvestId != null and harvestId != ''\">"+ "and harvest_id = #{harvestId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"harvestTime != null and harvestTime != ''\">"+ "and harvest_time = #{harvestTime} " + "</if>" + 
		  		  "<if test=\"number != null and number != ''\">"+ "and number = #{number} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"plotNumber != null and plotNumber != ''\">"+ "and plot_number = #{plotNumber} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_harvest (`batch`, `varieties`, `harvest_time`, `number`, `principal`, `telephone`, `plot_number`)"
	+ "values (#{batch}, #{varieties}, #{harvestTime}, #{number}, #{principal}, #{telephone}, #{plotNumber})")
	int save(HarvestDO harvest);
	
	@Update("<script>"+ 
			"update tb_harvest " + 
					"<set>" + 
		            "<if test=\"harvestId != null\">`harvest_id` = #{harvestId}, </if>" + 
                    "<if test=\"batch != null\">`batch` = #{batch}, </if>" + 
                    "<if test=\"varieties != null\">`varieties` = #{varieties}, </if>" + 
                    "<if test=\"harvestTime != null\">`harvest_time` = #{harvestTime}, </if>" + 
                    "<if test=\"number != null\">`number` = #{number}, </if>" + 
                    "<if test=\"principal != null\">`principal` = #{principal}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
                    "<if test=\"plotNumber != null\">`plot_number` = #{plotNumber}, </if>" + 
          					"</set>" + 
					"where harvest_id = #{harvestId}"+
			"</script>")
	int update(HarvestDO harvest);
	
	@Delete("delete from tb_harvest where harvest_id =#{harvestId}")
	int remove(Integer harvest_id);
	
	@Delete("<script>"+ 
			"delete from tb_harvest where harvest_id in " + 
					"<foreach item=\"harvestId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{harvestId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] harvestIds);
}
